package ouisseuk.gui;

import ouisseuk.model.Artist;
import ouisseuk.model.ReleaseFromArtist;

import com.flexycore.iphone.uikit.NSIndexPath;
import com.flexycore.iphone.uikit.UINavigationController;
import com.flexycore.iphone.uikit.UITableView;
import com.flexycore.iphone.uikit.UITableViewDelegate;
import com.flexycore.iphone.uikit.UIViewController;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
public class ReleasesFromArtistDelegate extends UITableViewDelegate {

	private Artist artist;
	private UINavigationController nav;

	/**
	 * Constructor
	 */
	public ReleasesFromArtistDelegate(Artist artist, UINavigationController nav) {
		super();
		init();
		this.artist = artist;
		this.nav = nav;
	}

	/**
	 * 
	 */
	@Override
	public void tableViewDidSelectRowAtIndexPath(UITableView tableView, NSIndexPath indexPath) {

		int row = indexPath.row();

		ReleaseFromArtist release = artist.getReleases().get(row);
		String rid = release.getRid();
		ReleaseView releaseView = new ReleaseView("http://www.discogs.com/release/" + rid + "?f=xml&api_key=52a1898466", nav);

		UIViewController viewController = null;

		viewController = new UIViewController().init();
		viewController.setTitle("Release");

		viewController.setView(releaseView);

		nav.pushViewControllerAnimated(viewController, true);

	}
}
